<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../resct18/react.development.js"></script>
    <script src="../resct18/react-dom.development.js"></script>
    <script src="../resct18/babel.min.js"></script>
</head>

<body>
    <div id="app"></div>
    <script type="text/babel">
        /* 
        porpa是用来做父子组件通信的
            -在父组件使用子组件的时候,可以给子组件添加属性
            -在子组件中组件实例的props属性上,可以拿到这个属性的值
        */

        class APP extends React.Component{   
            state={
                car:'八手奥拓'
            }
            render(){
                const {car} = this.state
                return (
                    <div>
                        <h1>我是父组件</h1>
                        <button onClick={this.changeCarHandle}>修改按钮</button>
                        <p>我开的车是{car}</p>
                        <Child car={car}/>
                    </div>
                )
            }
            changeCarHandle = ()=>{
                this.setState({car:'五菱宏光'})
            }
        }

        class Child extends React.Component{
            /* 
            当父组件更新状态的时候 子组件的render方法会重新执行生成新的虚拟DOM,也能拿到新的props
            */
            render(){
                const {car}=this.props
                return(
                    <p>我是儿子组件,我开我老子的车{car}</p>
                )
            }
        }
            
        
        

       const root=ReactDOM.createRoot(document.getElementById('app'));
       root.render(<APP/>)

    </script>
</body>

</html>